package com.hdw.job.batch.writer;

import com.hdw.common.base.mapper.BaseMapper;
import com.hdw.common.db.RoutingDataSource;
import com.hdw.common.db.ThreadLocalDataSource;
import com.hdw.common.util.DBUtil;
import org.springframework.batch.core.configuration.annotation.StepScope;
import org.springframework.batch.item.ItemWriter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * Created by liujunlei on 2021/5/25.
 */
@Component
@StepScope
public class InsertWriter implements ItemWriter {

    @Value("#{jobParameters['tableName']}")
    private String tableName;

    @Autowired
    BaseMapper baseMapper;

    @Override
    @RoutingDataSource
    public void write(List list) throws Exception {
        List<Map<String,Object>> mapList = (List<Map<String,Object>>)list;
        baseMapper.insertMapList(tableName,mapList.get(0),mapList);
    }
}
